<?php
/**
 * Created by PhpStorm.
 * User: yappy
 * Date: 17-1-13
 * Time: 上午11:35
 */
namespace common\components\notify;
use common\models\SysMessages;
use yii\base\Object;


class Handler extends Object
{
    private $notify;
    private $_user;

    public function __construct(SysMessages $message,$config=[])
    {
        $this->notify = $message;
        $this->_user = \Yii::$app->user;
        parent::__construct($config);
    }

    /**
     * 未读数量
     * @return int|string
     */
    public function getNoReadNums()
    {
        return $this->notify->find()->where(['to_member_id'=>$this->_user->id,'is_read'=>0])->count();
    }

    // 访问后个人所有通知更新为已读
    public function readAll()
    {
        return $this->notify->updateAll(['is_read' => 1], ['to_member_id'=> $this->_user->id,'is_read'=>0]);
    }


}